﻿@*
    列表视图工具栏
*@
@using NewLife;
@using NewLife.Cube
@using NewLife.Cube.Entity
@using NewLife.Web;
@using XCode;
@using NewLife.Cube.Extensions
@using XCode.Membership

@{
    var fact = ViewBag.Factory as IEntityFactory;
    var page = ViewBag.Page as Pager;
    var user = ViewBag.User as IUser ?? ManageProvider.User;
    var title = ViewBag.Title;
    var layoutSet = Parameter.GetOrAdd(user.ID, "LayoutSetting", ViewBag.Title as String, "table");
    var mode = layoutSet.Value;

    var act = Context.Request.Path + "";
    if (act.IsNullOrEmpty())
    {
        act = Url.Action("Index");
    }

    var set = ViewBag.PageSetting as PageSetting ?? PageSetting.Global;
    var stat = UserStat.FindByDate(DateTime.Today);
}

<!--begin::Toolbar 如果列表视图工具栏上方有仪表盘,设置pt-3 -->
<div class="d-flex flex-wrap flex-stack pt-0 pb-1">
    <!--begin::列表统计-->
    <div class="d-flex align-items-center justify-content-start">
        <div>
            <div class="d-flex align-items-center">
                <span class="fs-2x fw-bold text-gray-600 me-2">@(page != null ? page.TotalCount.ToString("n0") : 0)</span>
            </div>
            <span class="text-gray-400">当前用户总数</span>
        </div>
        <div class="bullet bg-secondary h-35px w-1px mx-3"></div>

        <div class="me-2">
            <div class="d-flex align-items-center">
                <span class="fs-2x fw-bold text-gray-600 me-2">@(stat != null ? stat.Actives.ToString("n0") : 0)</span>
            </div>
            <span class="text-gray-400">当前在线数</span>
        </div>
        <a href="~/Admin/UserOnline" class="btn btn-sm btn-light-primary btn-active-primary me-3"><span class="fas fa-user-check fs-md-2 me-1"></span>用户在线</a>
        <div class="bullet bg-secondary h-35px w-1px mx-3"></div>

        <div class="me-2">
            <div class="d-flex align-items-center">
                <span class="fs-2x fw-bold text-gray-600 me-2">@(stat != null ? stat.ActivesT30.ToString("n0") : 0)</span>
            </div>
            <span class="text-gray-400">最近30天活跃数</span>
        </div>
        <a href="~/Admin/UserStat" class="btn btn-sm btn-light-primary btn-active-primary">用户统计</a>
        <div class="bullet bg-secondary h-35px w-1px mx-3"></div>
    </div>
    <!--end::列表统计-->

    <!--begin::Controls-->
    <div class="d-flex">
        <!-- 新增按钮 -->
        @if (page != null)
        {
            var rv = page.GetRouteValue();
            if (set.EnableAdd && !set.IsReadOnly && this.Has(PermissionFlags.Insert))
            {
                <a href="@Url.Action("Add", rv)" class="btn btn-sm btn-icon btn-light-success btn-active-success w-70px" title="新增对象" data-bs-toggle="tooltip" data-bs-placement="top"><i class="fas fa-plus fs-md-2 me-3"></i>新增</a>
                <!-- 分隔条 -->
                <div class="bullet bg-secondary h-35px w-1px mx-3"></div>
            }
        }

        <!-- 批量操作 -->
        <div class="toolbar-batch">
            @await Html.PartialAsync("_List_Toolbar_Batch")
        </div>

        <!-- 自定义工具按钮 -->
        @await Html.PartialAsync("_List_Toolbar_Custom")

        <!--begin::列表模式-->
        <ul class="nav nav-pills me-2">
            <li class="nav-item m-0">
                <a class="btn btn-sm btn-icon btn-light btn-color-muted btn-active-primary me-3 mode @(mode.EqualIgnoreCase("card") ? "active" : "")" data-mode="card" data-bs-toggle="tab" href="#kt_card_pane">
                    <i class="fas fa-th-large fs-md-2"></i>
                </a>
            </li>
            <li class="nav-item me-2">
                <a class="btn btn-sm btn-icon btn-light btn-color-muted btn-active-primary mode @(mode.EqualIgnoreCase("table") ? "active" : "")" data-mode="table" data-bs-toggle="tab" href="#kt_table_pane">
                    <i class="fas fa-list fs-md-2"></i>
                </a>
            </li>
            <li class="nav-item m-0">
                <a class="btn btn-sm btn-icon btn-light btn-color-muted btn-active-primary" href="@Url.Action("Share")">
                    <i class="fas fa-share-alt fs-md-2"></i>
                </a>
            </li>
        </ul>
        <!--end::列表模式-->

        <!--begin::Wrapper-->
        @await Html.PartialAsync("_List_Toolbar_Adv")
        <!--end::Wrapper-->
    </div>
    <!--end::Controls-->
</div>
<!--end::Toolbar-->

<script>
    $(function(){
        var btn = $('ul.nav>li.nav-item>a.mode').click(function(){
            var mode = $(this).data("mode");
            var userid = @user.ID;
            var title = "@title";

            $.ajax({
                type: "POST",
                url: "/Cube/SaveLayout",
                data: {userid: userid, category: "LayoutSetting", name: title, value: mode},
                success: function(data){
                }
            });
        });
    });
</script>